import Vue from 'vue';
import Vuex from 'vuex';


Vue.use(Vuex);

const store = new Vuex.Store({
    state:{
		/**stationId:'',
		stationName:"",
		dstationShow:false,//站点不可视
		mydstationShow:false,
		**/
		token:localStorage.getItem('token') ? localStorage.getItem('token'):'',
		menuArray: [],			//	获取到的左侧导航
		currentJur: {},			//	控制每个页面的新增、编辑
		menuName: '',
	},
	
	//更改 Vuex 的 store 中的状态的唯一方法是提交 mutation，mutation 必须是同步函数，在 Vuex 中，mutation 都是同步事务
    mutations: {
    	/**getValue(state,stationName){
    		state.stationName=stationName.join(',')
    	},
        station_sure (state,station) {
        	state.dstationShow=false;
        	state.mydstationShow=false;
//	      	state.stationId=this.cities,
//	      	state.stationName=this.cities
	    },
	    dStationSelect(state){
	    	state.stationName="",
	    	state.dstationShow=true;
	    	state.mydstationShow=true;
	    },
	    station_cancel(state){
	    	state.dstationShow=false;
	    	state.mydstationShow=false;
	    },**/
	    changeLogin(state, user){
	      state.token = user.token;
	      localStorage.setItem('token', user.token);
		  
		},
		changeMenu(state, menu) {
			state.menuArray = menu
		},
		currentJur(state, current) {
			state.currentJur = current
		},
		menuName(state, current) {
			state.menuName = current
		},
		
	   	/*登录获取token*/
	   	$_setToken(state, value) { // 设置存储token
	        state.token = value;
	        localStorage.setItem('token', value);
	    },
	    /*退出清除token*/
	    $_removeStorage(state, value){  // 删除token
			  localStorage.removeItem('token');
	    },


    },
//		Action 类似于 mutation，不同在于：
//		Action 提交的是 mutation，而不是直接变更状态。
//		Action 可以包含任意异步操作
//		Action 通过 store.dispatch 方法触发
    actions: {//
        /**dStationSelect: ({ commit }) => commit('dStationSelect'),
        station_sure:({ commit })=>commit('station_sure'),
        station_cancel:({ commit })=>commit('station_cancel'),
        getValue:({ commit })=>commit('getValue'),
        setValue ({ commit, state }, stationName) {
    		state.stationName=stationName.value.join(',')
		},**/
		setMenu(context, Object) {
			context.commit('changeMenu', Object)
		},
		setCurrentJur(context, Object) {
			context.commit('currentJur', Object)
		},
		setMenuName(context, Object) {
			context.commit('menuName', Object)
		},
    },
    modules: {
//      app,
//      user
    },
    getters:{
    	/*dstationShow: state => state.dstationShow,
    	mydstationShow: state => state.mydstationShow,
    	stationId: state => state.stationId,
    	stationName: state => state.stationName,
    	checkAll: state => state.checkAll,
    	checkedCities: state => state.checkedCities,
    	cities: state => state.cities,
    	isIndeterminate: state => state.isIndeterminate,*/
    	// 监听数据变化的
    	getStorage(state){// 获取本地存储的登录信息
	      if(!state.token){
        	state.token =JSON.parse(localStorage.getItem(key))
	      }
	      return state.token
	    }

    }
});

export default store;
